import 'package:codersun/pages/flash_screen_page.dart';
import 'package:flutter/material.dart';
import 'package:codersun/pages/roots/category_page.dart';
import 'package:codersun/pages/roots/home_page.dart';
import 'package:codersun/pages/roots/setting_page.dart';
import 'package:codersun/pages/left_drawer.dart';

class Tabs extends StatefulWidget {
  final index;
  Tabs({Key key, this.index = 0}) : super(key: key);

  @override
  _TabsState createState() => _TabsState(index);
}

class _TabsState extends State<Tabs> {
  int currentIndex = 0;
  _TabsState(int index) {
    this.currentIndex = index;
  }

  bool _flashScreenComplection = false;

  List pages = [
    HomePage(),
    CategoryPage(),
    SettingPage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: (() {
        List<Widget> tempArr = List();

        tempArr.add(Scaffold(
          body: this.pages[this.currentIndex],
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: this.currentIndex,
            elevation: 0.0,
            backgroundColor: Colors.white,
            items: [
              BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
              BottomNavigationBarItem(icon: Icon(Icons.category), title: Text('Category')),
              BottomNavigationBarItem(icon: Icon(Icons.settings), title: Text('Setting')),
            ],
            onTap: (index) {
              setState(() {
                this.currentIndex = index;
              });
            },
          ),
          drawer: Drawer(
            child: LeftDrawer(),
          ),
          endDrawer: Drawer(
            child: Center(
              child: Text('右侧边栏'),
            ),
          ),
        ));

        if (_flashScreenComplection == false) {
          tempArr.add(Container(
            width: double.infinity,
            height: double.infinity,
            child: FlashScreenPage(
              completion: () {
                //
                _flashScreenComplection = true;
                setState(() {});
              },
            ),
          ));
        }

        return tempArr;
      })(),
    );
  }
}
